<?php
/*
 * employe/upload-cv.phtml
 */
    $this->headTitle("Téléchargement du fichier PDF pour le CV");
    $fichier = $this->fichier;

    $repUplCv = str_replace('public/', '', $this->repCv);    
?>

<div class="container-fluid">
    <div class="content-head">
        <h4>Télécharger un fichier PDF pour le CV</h4>
    </div>
    <div class="content-body">
        <div class="preview">
            <?php if (is_null($fichier)): ?>
                <?php if ($this->error) : ?>       
                    <div class="info"><?php echo $this->error; ?></div>
                <?php else: ?>            

                <?php endif; ?>
            <?php else: ?>
                <div class="cv-info">
                    <span>
                        <i class="cv-file"></i>
                        <?php echo $fichier; ?>
                    </span>
                </div>
                <div class="row">
                    <span class="cv-warning">Vous devez-valider pour prendre en compte le fichier</span>
                    <button id="cv-btn" class="btn btn-info" style="float: right;" onclick="validate();">Valider</button>
                </div>
            <?php endif; ?>
        </div>
        <form id="cv-form" class="well" action="<?php echo $this->url('RHX/default', array('controller' => 'employe', 'action' => 'uploadCv', 'id' => $this->matricule)) ?>" method="post" enctype="multipart/form-data">
            <input type="file" id="cv-file" name="cv" onchange="submit();" accept="">
            <input type="hidden" name="matricule" value="<?php echo (int) $this->matricule; ?>">
        </form>
    </div>
</div>

<script type="text/javascript">
    function validate() {
<?php if ((int) $this->matricule == 0): ?>
            cv = window.opener.document.getElementById('cv_');
            cv = $(cv);
            cv.text('<?php echo $fichier; ?>');
            dataCv = window.opener.document.getElementById('data-cv');
            dataCv = $(dataCv);
            dataCv.val('<?php echo $this->destination; ?>');
            dataCvExt = window.opener.document.getElementById('data-cv-ext');
            ext = $(dataCvExt);
            ext.val('<?php echo $this->extension; ?>');
            btn = window.opener.document.getElementById('cv-upload');
            btn = $(btn);
            btn.text('Changer le fichier');
<?php else: ?>
            cv = window.opener.document.getElementById('cv_link');
            cv = $(cv);
            cv.attr('href', '<?php echo $this->basePath() . '/'. $repUplCv . $this->destination ?>').show();
            
            btn = window.opener.document.getElementById('cv-upload');
            btn = $(btn);
            btn.text('Changer');
            
            ajax = $.ajax({
                type: 'post',
                url: '<?php echo $this->url('RHX/default', array('controller' => 'employe', 'action' => 'saveEmployeStringData')) ?>',
                data: '&pk=<?php echo $this->matricule; ?>&name=cv_path&value=' + encodeURI('<?php echo $this->destination; ?>')
            });
<?php endif; ?>
        window.close();
    }
</script>

<style type="text/css">
    .cv-file{
        display: inline-block;
        width: 32px;
        height: 32px;
        background: url('<?php echo $this->basePath() ?>/img/rhx/file-32x32.png') no-repeat;
    }
    .cv-info{
         background: none repeat scroll 0 0 #DEDEDE;
	border: 1px solid #CCCCCC;
	color: #555555;
	display: block;
	margin: 5px auto;
	width: 99%;
    }
    .cv-info span{
        line-height: 32px;
    }
    #cv-form{
        position: absolute;
        bottom: -20px;
        left: 0px;
        width: 100%;
    }
    #cv-form [type=file]{
        color: red;
    }
    .cv-warning{
        font-size: 0.9em;
        color: #6666ff;
        font-style: italic;
        text-indent: 5px;
    }
</style>